#include "Mesh.h"
#include "../Core/glExt.h"
#include "../View/RenderContext.h"
#include <algorithm>
#include <functional>
#include "../Core/GlPlatform.h"

namespace Model {
	Mesh::Mesh() : mOrigin(0,0,0) {
	}

	Mesh::~Mesh() {
	}

	void Mesh::setupTransform() {
		Core::glExt::transform( mTransform );
	}

	void Mesh::render( View::RenderContext& rx ) {
		using namespace std::placeholders;
		glPushMatrix(); {
			Core::glExt::translate( mOrigin );
			setupTransform();
			onRender( rx );
			
			if ( !mSubmeshes.empty() )
				std::for_each( mSubmeshes.begin(), mSubmeshes.end(), std::bind( &Mesh::render, _1, rx ) );
		} glPopMatrix();
	}

	void Mesh::onRender( View::RenderContext& rx ) {

	}
}